package com.example.administrator.compileapp.activity;

import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.android.databinding.library.baseAdapters.BR;
import com.example.administrator.compileapp.R;
import com.example.administrator.compileapp.bean.TeacherEntity;
import com.example.administrator.compileapp.databinding.ActivityOtherButtonBinding;
import com.example.administrator.compileapp.until.CommentRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

public class OtherButtonActivity extends AppCompatActivity {
  private ActivityOtherButtonBinding binding;
    private CommentRecyclerAdapter<Object> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       binding= DataBindingUtil.setContentView(this,R.layout.activity_other_button);
        aboutIntentExtra();
        aboutOnClick();
    }

    private void aboutOnClick() {
        binding.otherButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void aboutIntentExtra() {
        String title= getIntent().getStringExtra("title");
        binding.otherButtonTitle.setText(title);
        if(title.equals("课程简介")){
            String[] class1 = getResources().getStringArray(R.array.class1);
            binding.otherButtonContent.setVisibility(View.VISIBLE);
            binding.otherButtonContent.setText("        "+class1[0]);
        }else if(title.equals("学习目标")){
            aboutStudyAim();
        }else if(title.equals("教师简介")){
            binding.otherButtonLinear.setVisibility(View.VISIBLE);
            aboutTeacher();
        }else if(title.equals("学习帮助")){
            aboutStudyHelp();
        }
    }

    private void aboutStudyHelp() {
        List<TeacherEntity> list = new ArrayList<>();
        String[] strings = getResources().getStringArray(R.array.studyhelp1);
        String[] string = getResources().getStringArray(R.array.studyhelp2);
        TeacherEntity entity = new TeacherEntity(strings[0],strings[1],null,null,null,null,null,null);
        TeacherEntity entity2 = new TeacherEntity(string[0],string[1],null,null,null,null,null,null);
        Log.d("1620",entity.toString());
        list.add(entity);
        list.add(entity2);
        adapter = new CommentRecyclerAdapter<Object>(this,new ArrayList<>(), R.layout.teacher_item,BR.teacherEntity);
        binding.recycler.setAdapter(adapter);
        adapter.addAll(list);
    }

    private void aboutTeacher() {
        List<TeacherEntity> list = new ArrayList<>();
        String[] strings = getResources().getStringArray(R.array.teacher1);
        String[] string = getResources().getStringArray(R.array.teacher2);
        String[] string2 = getResources().getStringArray(R.array.teacher3);
        TeacherEntity entity = new TeacherEntity(strings[0],strings[1],strings[2],strings[3],strings[4],strings[5],strings[6],null);
        TeacherEntity entity2 = new TeacherEntity(string[0],string[1],string[2],string[3],null,null,null,null);
        TeacherEntity entity3 = new TeacherEntity(string2[0],string2[1],null,null,null,null,null,null);
        list.add(entity);
        list.add(entity2);
        list.add(entity3);
        adapter = new CommentRecyclerAdapter<Object>(this,new ArrayList<>(), R.layout.teacher_item,BR.teacherEntity);
        binding.recycler.setAdapter(adapter);
        adapter.addAll(list);
    }

    private void aboutStudyAim() {
        String[] studyAim = getResources().getStringArray(R.array.studyaim);
        List<String> strings = new ArrayList<>();
        for (int i = 0; i < studyAim.length; i++) {
            strings.add("        "+studyAim[i]);
        }
        adapter = new CommentRecyclerAdapter<Object>(this,new ArrayList<>(),R.layout.go_item,BR.string);
        adapter.addAll(strings);
        binding.recycler.setAdapter(adapter);
    }
}
